package sadmin

import (
	"encoding/json"
	"github.com/astaxie/beego"
	"shop/models/sadmin"
)

type FaqController struct {
	beego.Controller
}
//@Title questionadd
//@Description 问题添加
//@Param body body sadmin.Faq true "d"
//@Success 200 ok
//@router /faq/add/ [post]
func (c *FaqController)FaqAdd()  {
	var com sadmin.Faq
	json.Unmarshal(c.Ctx.Input.RequestBody,&com)
	err:=sadmin.FaqAdd(com)
	if err!=nil{
		c.Ctx.ResponseWriter.WriteHeader(201)
		c.Data["json"]=err.Error()
	}else {
		c.Ctx.ResponseWriter.WriteHeader(200)
		c.Data["json"]="ok"
	}
	c.ServeJSON()
}
//@Title faqshow
//@Description 展示问题信息
//@Success 200 {object} sadmin.Faq
//@router /faqshow [get]
func (c *FaqController)FaqShow()  {
	var com []sadmin.Faq
	com, err := sadmin.FaqShow()
	if err != nil {
		c.Data["json"] = err.Error()
	} else {
		c.Ctx.ResponseWriter.WriteHeader(200)
		c.Data["json"] = com
	}

	c.ServeJSON()
}
// @Title faqdel
// @Description 删除问题
// @Param	id		path 	int	true		"The id of type"
// @Success 200 ok
// @router /faq/del/:id [delete]
func (c *FaqController)FaqDel()  {
	idd,_:=c.GetInt(":id")
	err:=sadmin.FaqDel(idd)
	if err!=nil{
		c.Ctx.ResponseWriter.WriteHeader(201)
		c.Data["json"]=err.Error()
	}else {
		c.Ctx.ResponseWriter.WriteHeader(200)
		c.Data["json"]="ok"
	}
	c.ServeJSON()
}